Clip
逐元素将输入裁剪到闭区间 \([\mathrm{min},\, \mathrm{max}]\)。
\[\mathrm{dst}_i = \max(\mathrm{min},\, \min(\mathrm{src}_i,\, \mathrm{max}))\]
- 输入:
src - 输入数据地址
length - 计算元素个数
min - 裁剪下限
max - 裁剪上限
core_mask - 核掩码(仅共享存储版本使用)
- 输出:
dst - 输出数据地址,长度与
src相同
- 支持平台:
FT78NEMT7004
备注
FT78NE 支持 int8、int16、int32、fp32、fp64
MT7004 支持 int16、int32、fp16、fp32
共享存储版本:
-
void i8_clip_s(int8_t *src, int8_t *dst, int length, int8_t min, int8_t max, int core_mask)
-
void i16_clip_s(int16_t *src, int16_t *dst, int length, int16_t min, int16_t max, int core_mask)
-
void i32_clip_s(int32_t *src, int32_t *dst, int length, int32_t min, int32_t max, int core_mask)
-
void hp_clip_s(float16 *src, float16 *dst, int length, float16 min, float16 max, int core_mask)
-
void fp_clip_s(float *src, float *dst, int length, float min, float max, int core_mask)
-
void dp_clip_s(double *src, double *dst, int length, double min, double max, int core_mask)
C调用示例:
1// MT7004 示例(共享存储多核,DDR 地址)
2void TestClipSMCFp32(int length, int core_mask) {
3 int core_id = get_core_id();
4 int logic_core_id = GetLogicCoreId(core_mask, core_id);
5 int core_num = GetCoreNum(core_mask);
6 float *src = (float *)0x81000000;
7 float *dst = (float *)0x82000000;
8 float min = 0.0f;
9 float max = 6.0f;
10 sys_bar(0, core_num);
11 fp_clip_s(src, dst, length, min, max, core_mask);
12}
13
14void main() {
15 int core_mask = 0b1111;
16 TestClipSMCFp32(1024, core_mask);
17}
私有存储版本:
-
void i8_clip_p(int8_t *src, int8_t *dst, int length, int8_t min, int8_t max)
-
void i16_clip_p(int16_t *src, int16_t *dst, int length, int16_t min, int16_t max)
-
void i32_clip_p(int32_t *src, int32_t *dst, int length, int32_t min, int32_t max)
-
void hp_clip_p(float16 *src, float16 *dst, int length, float16 min, float16 max)
-
void fp_clip_p(float *src, float *dst, int length, float min, float max)
-
void dp_clip_p(double *src, double *dst, int length, double min, double max)
C调用示例:
1// MT7004 示例(私有存储单核,AM 地址)
2void TestClipAMFp32(int length) {
3 float *src = (float *)0x10010000;
4 float *dst = (float *)0x10020000;
5 float min = -1.0f;
6 float max = 1.0f;
7 fp_clip_p(src, dst, length, min, max);
8}
9
10void main() {
11 TestClipAMFp32(1024);
12}